<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>分类参数</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card style="margin-top:20px;">
      <el-row :gutter="50">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryinfo.query" clearable @clear="getOrdersList">
            <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table :data="ordersList" border stripe style="width:100%;">
        <el-table-column prop="order_number" label="订单编号" width="450"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否💴">
          <template slot-scope="scope">
            <el-button type="success" size="mini" v-if="scope.row.pay_status !==0">💴已付</el-button>
            <el-button type="danger" size="mini" v-else>💴未付</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column label="下单时间" width="180">
          <template slot-scope="scope">{{scope.row.create_time | time}}</template>
        </el-table-column>
        <el-table-column label="操作" width="280">
          <template>
            <el-button type="success" size="mini" @click="editedizhi">📡修改地址</el-button>
            <el-button type="warning" size="mini" @click="wuliuxinxi">✉物流信息</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog title="修改地址" :visible.sync="ediDialogVisible" width="50%" @close="ediClose">
      <el-form :model="ediForm" :rules="ediFormRules" ref="ediFormRef" label-width="100px">
        <!-- 级联选择器 -->
        <el-form-item label="省市县">
          <el-cascader change-on-select v-model="ediForm.order_fapiao_company" :options="citydata"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="order_fapiao_content">
          <el-input v-model="ediForm.order_fapiao_content"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="ediDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="ediDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 修改地址对话框 -->
    <el-dialog title="物流信息" :visible.sync="wuliuDialogVisible" width="50%">
      <el-timeline reverse>
        <el-timeline-item
          v-for="(activity, index) in wuliu"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>
<script>
import citydata from "./citydata";
export default {
  created() {
    this.getOrdersList();
  },
  data() {
    return {
      queryinfo: {
        query: "",
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      ordersList: [],
      ediDialogVisible: false,
      ediForm: {
        order_fapiao_company: [],
        order_fapiao_content: ""
      },
      ediFormRules: {
        order_fapiao_company: [
          { required: true, message: "请输入省市县", trigger: "blur" }
        ],
        order_fapiao_content: [
          { required: true, message: "请输入详细地址", trigger: "blur" }
        ]
      },
      citydata,
      wuliu: [],
      wuliuDialogVisible: false
    };
  },
  methods: {
    async getOrdersList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryinfo
      });
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.ordersList = res.data.goods;
      this.total = res.data.total;
      console.log(this.ordersList);
    },
    // 搜索方法
    search() {},
    editedizhi() {
      this.ediDialogVisible = true;
    },
    ediClose() {
      this.$refs.ediFormRef.resetFields();
    },
    async wuliuxinxi() {
      const { data: res } = await this.$http.get("/kuaidi/" + "1106975712662");
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.wuliu = res.data;
      this.wuliuDialogVisible = true;
    },
    handleSizeChange(newsize){
        this.queryinfo.pagesize=newsize
        this.getOrdersList()
    },
    handleCurrentChange(newnum){
        this.queryinfo.pagenum=newnum
        this.getOrdersList()
    }
  }
};
</script>
<style lang="less" scoped>
</style>